import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '首页',
      component: () => import('@/views/Admin/index'),
      meta: { title: '管理员管理', icon: 'dashboard' }
    }]
  }, 
  {
    path: '/',
    component: Layout,
    children: [{
      path: 'hello',
      name: '登陆界面',
      component: () => import('@/views/Admin/hello'),
      meta: { title: '后台登录', icon: 'dashboard' }
    }]
  }, {
    path: '/Exam',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Exam',
        component: () => import('@/views/Exam/index'),
        meta: { title: '考试管理', icon: 'el-icon-s-operation' }
      }
    ]
  }, {
    path: '/Exam',
    component: Layout,
    children: [
      {
        path: 'add',
        name: 'ExamAdd',
        component: () => import('@/views/Exam/add'),
        meta: { title: '添加考试', icon: 'el-icon-plus' }
      }
    ]
  },{
    path: '/Exam',
    component: Layout,
    children: [
      {
        path: 'query',
        name: 'ExamQuery',
        component: () => import('@/views/Exam/query'),
        meta: { title: '考试查询', icon: 'el-icon-search' }
      }
    ]
  },{
    path: '/Questions',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Questions',
        component: () => import('@/views/Questions/index'),
        meta: { title: '考试试题', icon: 'el-icon-s-operation' }
      }
    ]
  },{
    path: '/Questions',
    component: Layout,
    children: [
      {
        path: 'query',
        name: 'QuestionsQuery',
        component: () => import('@/views/Questions/query'),
        meta: { title: '题目列表', icon: 'el-icon-search' }
      }
    ]
  },{
    path: '/Questions',
    component: Layout,
    children: [
      {
        path: 'add',
        name: 'QuestionsAdd',
        component: () => import('@/views/Questions/add'),
        meta: { title: '添加题目', icon:
          'el-icon-plus' }
      }
    ]
  },{
    path: '/Questions',
    component: Layout,
    children: [
      {
        path: 'adddetail',
        name: 'AddDetail',
        component: () => import('@/views/Questions/AddDetail')
      }
    ]
  },
  {
    path: '/ExamStudent',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'ExamStudent',
        component: () => import('@/views/ExamStudent/index'),
        meta: { title: '考试&学生', icon: 'el-icon-s-operation' }
      }
    ]
  }, {
    path: '/ExamDetail',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'ExamDetail',
        component: () => import('@/views/ExamDetail/index'),
        meta: { title: '考试详情', icon: 'el-icon-s-operation' }
      }
    ]
  }, {
    path: '/Student',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Student',
        component: () => import('@/views/Student/index'),
        meta: { title: '学生信息', icon: 'el-icon-s-operation' }
      }
    ]
  }, {
    path: '/TakeExam',
    component: () => import('@/views/TakeExam/stuIndex'),
    children: [
      {
        path: 'stuIndex',
        name: 'stuIndex',
        component: () => import('@/views/TakeExam/index'),
        meta: { title: '学生信息', icon: 'el-icon-s-operation' }
      },
      {
        path: 'stuExam',
        name: 'stuExam',
        component: () => import('@/views/StuExam/index'),
        meta: { title: '学生信息', icon: 'el-icon-s-operation' }
      },
      {
        path: 'info',
        name: 'info',
        component: () => import('@/views/Info/index'),
        meta: { title: '学生信息', icon: 'el-icon-s-operation' }
      },
      {
        path: 'examMsg',
        name: 'examMsg',
        component: () => import('@/views/TakeExam/examMsg'),
        meta: { title: '学生信息', icon: 'el-icon-s-operation' }
      },
      {
        path: 'answer',
        name: 'answer',
        component: () => import('@/views/TakeExam/answer'),
        meta: { title: '学生信息', icon: 'el-icon-s-operation' }
      },
    ]
  },{
    path: '/Teacher',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Teacher',
        component: () => import('@/views/Teacher/index'),
        meta: { title: '老师信息', icon: 'el-icon-s-operation' }
      }
    ]
  },
  {
    path: '/Info',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Info',
        component: () => import('@/views/Info/index'),
        meta: { title: '个人信息', icon: 'el-icon-s-operation' }
      }
    ]
  },
  {
    path: '/StuExam',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'StuExam',
        component: () => import('@/views/StuExam/index'),
        meta: { title: '考试详情', icon: 'el-icon-s-operation' }
      }
    ]
  },
  {
    path: '/TakeExam',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'TakeExam',
        component: () => import('@/views/TakeExam/index'),
        meta: { title: '考试系统', icon: 'el-icon-s-operation' }
      }
    ]
  },
  {
    path: '/TakeExam',
    component: Layout,
    children: [
      {
        path: 'examMsg',
        name: 'examMsg',
        component: () => import('@/views/TakeExam/examMsg')
      }
    ]
  },
  {
    path: '/TakeExam',
    component: Layout,
    children: [
      {
        path: 'answer',
        name: 'answer',
        component: () => import('@/views/TakeExam/answer')
      }
    ]
  },
  {
    path: '/echarts',
    component: Layout,
    children: [
      {
        path: 'index/:id',
        name: 'echarts',
        component: () => import('@/views/Echarts/index.vue'),
        meta: { title: '考试分析', icon: 'el-icon-s-operation' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
